#ifndef DICTENGINE_H
#define DICTENGINE_H

#include <QObject>
//#include <QList>

class QFile;
class QTextStream;
class QStringList;

/*	DictOccurrence holds the location and length pair for one occurrence of a term	*/
class DictOccurrence {
public:
	DictOccurrence(QString _position, QString _length)
		: pos(_position), length(_length) {}
	DictOccurrence() {}
	QString pos;
	QString length;
};

/*	DictRecord holds heading and a list of positions and lengths in .dict file	*/
class DictRecord {
public:
	DictRecord(QString _heading, QString _position, QString _length)
		: heading(_heading){
		occ.append(DictOccurrence(_position, _length));
	}
	QString heading;
	QList<DictOccurrence> occ;
};

class DictEngine : public QObject
{
	Q_OBJECT
public:
	explicit DictEngine(QString path, QString name, QObject *parent = 0);
	~DictEngine();

	QStringList suggestions(QString query);
	QString meaning(int index);

	QString name() const;
	QString databaseName() const;

	static const int max_index_line_length = 300;
	static int number_of_suggestions;

private:
	QFile *indexFileHandle;
	QTextStream	*streamIndex;
	QFile *dictFileHandle;
	QTextStream *streamDict;
	qint64 indexEndPos;
	QString datName;
	QList<DictRecord> *sugg;		/* List containing suggestions and their	*/
									/* positions and lengths in the .dict file	*/

	qint64 findFirstEntry(QString query) const;
	QStringList entryAt(qint64 pos) const;
	qint64 base64toInt(QString str) const;
	DictRecord readLineIE();
	QString locToASCII(QString input) const;

};

#endif // DICTENGINE_H
